package com.liuzu.esys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.mapper.GoodMapper;
import com.liuzu.esys.mapper.GoodPushMapper;
import com.liuzu.esys.pojo.Good;
import com.liuzu.esys.pojo.GoodPush;
import com.liuzu.esys.service.GoodPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("goodPushService")
public class GoodPushServiceImpl implements GoodPushService {

    @Autowired
    private GoodPushMapper goodPushMapper;

    @Override
    public List<GoodPush> GoodPushList() {
        return null;
    }

    @Override
    public LayuiPageVo<GoodPush> goodPushPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);

        List<GoodPush> goodPush = goodPushMapper.selectByParams(params);

        PageInfo<GoodPush> goodPushPageInfo = new PageInfo<>(goodPush);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中

        LayuiPageVo<GoodPush> goodPushLayuiPageVo = new LayuiPageVo<>();
        goodPushLayuiPageVo.setCode(0);
        goodPushLayuiPageVo.setMsg("分页数据列表");
        // xxxxxxxxxxxxxxxxxx
        goodPushLayuiPageVo.setCount(goodPushPageInfo.getTotal());
        goodPushLayuiPageVo.setData(goodPushPageInfo.getList());
        return goodPushLayuiPageVo;
    }

    @Override
    public int deleteGoodPush(Integer id) {
        return goodPushMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateGoodPush(GoodPush goodPush) {
        int i = goodPushMapper.updateByPrimaryKeySelective(goodPush);
        return i;
    }

    @Override
    public int addGoodPush(GoodPush goodPush) {
        int i = goodPushMapper.insertSelective(goodPush);
        return i;
    }

    @Override
    public LayuiPageVo<GoodPush> userPushPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);

        List<GoodPush> goodPush = goodPushMapper.goodPush(params);

        PageInfo<GoodPush> goodPushPageInfo = new PageInfo<>(goodPush);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中

        LayuiPageVo<GoodPush> goodPushLayuiPageVo = new LayuiPageVo<>();
        goodPushLayuiPageVo.setCode(0);
        goodPushLayuiPageVo.setMsg("分页数据列表");
        // xxxxxxxxxxxxxxxxxx
        goodPushLayuiPageVo.setCount(goodPushPageInfo.getTotal());
        goodPushLayuiPageVo.setData(goodPushPageInfo.getList());
        return goodPushLayuiPageVo;
    }
}
